package org.example.linkedlist;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/05/28 20:03
 */
@Deprecated
public class Solution206 {

    public static void main(String[] args) {
        Solution206 solution206 = new Solution206();
        ListNode head = new ListNode();
        head.val = 1;
        head.next = new ListNode(2, new ListNode(3, new ListNode(4, new ListNode(5))));

        ListNode result = solution206.reverseList(head);
        ListNode print = result;
        while (print != null){
            System.out.print(print.val);
            print = print.next;
            if(print != null){
                System.out.print("->");
            }
        }
        System.out.println(" ");
    }

    public ListNode reverseList(ListNode head) {
        ListNode prev = null;
        ListNode curr = head;
        while (curr != null){
            ListNode next = curr.next;
            curr.next = prev;
            prev = curr;
            curr = next;
        }
        return prev;
    }
}
